package com.htt.app.doctruyendemkhuya_joyfm.view;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.htt.app.doctruyendemkhuya_joyfm.PLayerService;
import com.htt.app.doctruyendemkhuya_joyfm.R;
import com.htt.app.doctruyendemkhuya_joyfm.clock.Clock;
import com.htt.app.doctruyendemkhuya_joyfm.object.Show;

public class PlayerView implements SeekBar.OnSeekBarChangeListener, OnClickListener{
	public static Activity activity;
	
	public boolean isCreate = false;
	public static boolean isPlaying = false;
	public static boolean isPreparing = false;
	
	public static Show show = null; 
	
	private static final String TAG = "PlayerView";
	
	// header
	public static TextView tvHeaderTitle;
	public static ImageButton btnHome;
	public static ImageButton btnStar;
	public static TextView tvHeaderDes;
		
	// image view
	public static ImageView imgView;
	
	// timer
	public static Clock clock = null;
	public static TextView tvTimerCurrent;
	public static TextView tvTimerTotal;
	public static SeekBar sbTimer;
	
	// button play, (pause), previous, reload
	public static ImageButton btnPlay,btnForward, btnBackward,
				btnPrevious, btnNext;
	
	public static TextView tvHenGio;
	
	private View view;
	
	public static Intent playerService;
	public View createView(Activity ctx, Show c) {
		// TODO Auto-generated constructor stub
		
		activity = ctx;
		
		initializeUIElements();
		
		if(PLayerService.listended != null) {
			
			PlayerView.show = PLayerService.listended;
			
			playerService = new Intent(ctx, PLayerService.class);
			playerService.putExtra("Media", PLayerService.isRunMedia);
			ctx.startService(playerService);
			
		} else {
		
			PlayerView.show = c;
			
			playerService = new Intent(ctx, PLayerService.class);
			playerService.putExtra("Media", PLayerService.isRunMedia);
			ctx.startService(playerService);
		}

		return view;
	}

	/**
	 * Function to play
	 * */
	public void  play(Show show) {
			
			PlayerView.show = show;
			
			playerService = new Intent(activity, PLayerService.class);
			playerService.putExtra("Media", 1);
			activity.startService(playerService);
				
	}
	
	public View getView() {
		return view;
	}
	
	private void initializeUIElements() {
		view = LayoutInflater.from(activity).inflate(R.layout.player, null);

		tvHeaderTitle = (TextView) view.findViewById(R.id.player_header_title);
		tvHeaderDes = (TextView) view.findViewById(R.id.player_header_des);
		btnHome = (ImageButton) view.findViewById(R.id.player_header_home);
		btnStar = (ImageButton) view.findViewById(R.id.player_header_star);
		
		imgView = (ImageView) view.findViewById(R.id.player_img_view);
		
		tvTimerCurrent = (TextView) view.findViewById(R.id.player_textview_currentDuration);
		tvTimerTotal = (TextView) view.findViewById(R.id.player_textview_totalDuration);
		sbTimer = (SeekBar) view.findViewById(R.id.player_progressBar_timer);
		
		btnPlay = (ImageButton) view.findViewById(R.id.player_btn_play);
		btnPlay.setImageResource(R.drawable.btn_play);
		btnPrevious = (ImageButton) view.findViewById(R.id.player_btn_previous);
		btnNext = (ImageButton) view.findViewById(R.id.player_btn_next);
		btnForward = (ImageButton) view.findViewById(R.id.player_btn_forward);
		btnBackward = (ImageButton) view.findViewById(R.id.player_btn_backward);
		
		tvHenGio = (TextView) view.findViewById(R.id.player_tv_hen_gio);
		
		isCreate = true;
		
		btnHome.setOnClickListener(this);
		btnStar.setOnClickListener(this);
		btnNext.setOnClickListener(this);
		btnPrevious.setOnClickListener(this);
		btnPlay.setOnClickListener(this);
		btnForward.setOnClickListener(this);
		btnBackward.setOnClickListener(this);
		tvHenGio.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress,
			boolean fromUser) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}

}
